Skip to content

Fix string negative indexing#323

Merged
softmattertheory merged 1 commit into
Morpho-lang:devfrom
WoodchuckXL:strindex
Jul 7, 2026
Merged

Fix string negative indexing#323
softmattertheory merged 1 commit into
Morpho-lang:devfrom
WoodchuckXL:strindex

Conversation

@WoodchuckXL

Copy link
Copy Markdown

Fix for bug #321. Strings now throw an error if the user attempts to index them negatively. Added a test to the suite to check for this behavior.

Internally, this bug appeared because the string index operation was calling the enumerate function instead of a dedicated get index function.

@softmattertheory

Copy link
Copy Markdown
Contributor

Thanks for the contribution. One thing I'm wondering here is whether string indexing should match List (where a negative index means count from the end... or throw an error). It might be worth looking at what other languages do.

@softmattertheory

Copy link
Copy Markdown
Contributor

We decided that, for now, it's better to alert the user of potential out-of-bounds access. List, Matrix and Tuple all permit negative indices, but the use-case for String is less clear.

@softmattertheory
softmattertheory merged commit ec033a6 into Morpho-lang:dev Jul 7, 2026
6 checks passed
@WoodchuckXL
WoodchuckXL deleted the strindex branch July 13, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants